use std::io::Write;
pub enum ShopList {
    // name (name, price, effect)
    Hill(String, u8, u8),    //hill player
    Attack(String, u8, u8),  //add attack for player
    Deffend(String, u8, u8), //add def fo player
    Health(String, u8, u8),  //add max hp fo player
}

impl ShopList {
    pub fn shops_menu() {
        let hill = ShopList::Hill("hill".to_string(), 10, 5);
        let attack = ShopList::Attack("attack".to_string(), 10, 5);
        let deffend = ShopList::Deffend("def".to_string(), 10, 5);
        let health = ShopList::Health("health".to_string(), 10, 5);
        let shop_menu_list = [
            "\nМагазин:",
            "1. Хилл",
            "2. Атака",
            "3. Защита",
            "4. Увеличить ХП",
            "0. Выход",
        ];
        for el in shop_menu_list {
            println!("{}", el);
        }
        let item: (String, u8, u8) = loop {
            print!("Enter num [SHOP] >> ");
            std::io::stdout().flush().expect("some error");
            let mut input = String::new();
            std::io::stdin().read_line(&mut input).expect("wrong line");
            let input: u8 = match input.trim().parse() {
                Ok(n) => n,
                Err(err) => {
                    println!("{:?}", err);
                    0
                }
            };
            match input {
                0 => break ("none".to_string(), 0, 0),
                1 => break Self::take_item(hill),
                2 => break Self::take_item(attack),
                3 => break Self::take_item(deffend),
                4 => break Self::take_item(health),
                _ => {
                    for el in shop_menu_list {
                        println!("{}", el);
                    }
                    ("none".to_string(), 0, 0)
                }
            };
        };

        println!("{:?}", item);
    }
    fn take_item(sl: ShopList) -> (String, u8, u8) {
        match sl {
            ShopList::Hill(name, price, effect) => (name, price, effect),
            ShopList::Attack(name, price, effect) => (name, price, effect),
            ShopList::Deffend(name, price, effect) => (name, price, effect),
            ShopList::Health(name, price, effect) => (name, price, effect),
        }
    }
}
